package com.example.leetcode.leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author haitao
 * @date 2021/10/29 3:52 下午
 */
public class Solution49 {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = Arrays.stream(strs).parallel().collect(Collectors.groupingBy(s -> {
            char[] sortKeyArray = s.toCharArray();
            Arrays.sort(sortKeyArray);
            return Arrays.toString(sortKeyArray);
        }));
        return new ArrayList<>(map.values());
    }

    public static void main(String[] args) {
        Solution49 solution49 = new Solution49();
        String [] strs = new String[]{"eat", "tea", "tan", "ate", "nat", "bat"};
        System.out.println(solution49.groupAnagrams(strs));
    }
}
